﻿# -*- coding: utf-8 -*-
import os,logging
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext.db import Model as DBModel
from google.appengine.api import memcache
from google.appengine.api import mail
from google.appengine.api import urlfetch
from google.appengine.api import datastore
from datetime import datetime

class Blog(db.Model):
    owner = db.UserProperty()
    description = db.TextProperty()
    title = db.StringProperty(multiline=False,default='Ficolog')
    subtitle = db.StringProperty(multiline=False,default='This is a ficolog.')
    entrycount = db.IntegerProperty(default=0)
    posts_per_page= db.IntegerProperty(default=10)
    feedurl = db.StringProperty(multiline=False,default='/feed')
    #enable_memcache = db.BooleanProperty(default = False)
    domain=db.StringProperty()
    show_excerpt=db.BooleanProperty(default=True)
    version=0.01
    timedelta=db.FloatProperty(default=8.0)# hours
    language=db.StringProperty(default="en-us")


    def save(self):
        self.put()

    def initialsetup(self):
        self.title = 'Your Blog Title'
        self.subtitle = 'Your Blog Subtitle'


    def hotposts(self):
        return Entry.all().filter('entrytype =','post').filter("published =", True).order('-readtimes').fetch(8)

    def recentposts(self):
        return Entry.all().filter('entrytype =','post').filter("published =", True).order('-date').fetch(8)

    def postscount(self):
        return Entry.all().filter('entrytype =','post').filter("published =", True).order('-date').count()
    
    

class Entry(db.Model):
    author = db.UserProperty()
    author_name = db.StringProperty()
    published = db.BooleanProperty(default=False)
    content = db.TextProperty(default='')
    readtimes = db.IntegerProperty(default=0)
    title = db.StringProperty(multiline=False,default='')
    date = db.DateTimeProperty(auto_now_add=True)
    mod_date = db.DateTimeProperty(auto_now_add=True)
    tags = db.StringListProperty()
    categorie_keys=db.ListProperty(db.Key)
    allow_comment = db.BooleanProperty(default=True) #allow comment
    #keep in top
    sticky=db.BooleanProperty(default=False)
    
    
    